﻿using System.Windows;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;

namespace Eswat.Client.Wpf
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		private readonly IUnityContainer _container;

		/// <summary>
		/// Initializes a new instance of the <see cref="App"/> class.
		/// </summary>
		/// <exception cref="T:System.InvalidOperationException">More than one instance of the <see cref="T:System.Windows.Application"/> class is created per <see cref="T:System.AppDomain"/>.</exception>
		public App()
		{
			this._container = new UnityContainer();

			var locator = new UnityServiceLocator(this._container);

			ServiceLocator.SetLocatorProvider(() => locator);

			DependencyManager.LoadFromConfiguration(
				testService =>
					this._container.RegisterInstance<ITestService>(
						testService.Name,
						testService,
						new ContainerControlledLifetimeManager()),
				testResultLoggingService =>
					this._container.RegisterInstance<ITestResultLoggingService>(
						testResultLoggingService,
						new ContainerControlledLifetimeManager()));
		}

		/// <summary>
		/// Raises the <see cref="E:System.Windows.Application.Startup"/> event.
		/// </summary>
		/// <param name="e">A <see cref="T:System.Windows.StartupEventArgs"/> that contains the event data.</param>
		protected override void OnStartup(StartupEventArgs e)
		{
			base.OnStartup(e);
		}
	}
}
